home *** CD-ROM | disk | FTP | other *** search
- Forwarded Message:
- From: MenTaT - !Productions <mentat@sefl.satelnet.org>
- Date: Tue, 31 Jan 1995 15:30:31 -0500 (EST)
- Subject: Re: Recursive programming (Re: Paint, et all.)
- To: "stud.ass." <bcollin@mpi.nl>
-
- >
- > > How does recursive programming work? Suppose I wanted to make a
- > > MineSweeper clone, how would I let the computer show all the
- > > fields that aren't surrounded by a bomb whenever I hit a field
- > > which is not surrounded by a bomb?
- > > Mind, I'm not trying to make a clone here, I just thought it's
- > > the best way to illustrate whatever I try to... well, er, try,
- > > really :)
- > >
- >
- > Recursive programming works by calling a procedure from itself.
- > i.e.:
- > Procedure Test[A]
- > Inc A
- > If A<10 Then Test[A]
- > End proc
- >
- > I am not sure this example will work in Amos, though. I seem to
- > remember that Amos has some limitations on recursion, for
- instance
- > that the procedure calls may not be nested more than 15 times,
- > which makes it useless for most applications.
-
- You need to do a Set Buffer (or something similar). I wrote an
- ATOMS
- clone once, and occasionally it would get about 3 or 4 thousand
- levels
- deep. :)
-
- > BTW, why would you want to use recursion for this Mines-clone.
- You
- > could just check the array, could you not?
-
- You could, but recursion makes it MUCH easier... Just do this :
-
- Procedure SHOWMINES[X,Y]
-
- If GRID(X-1,Y)=0
- SHOWMINES[X-1,Y]
- End If
- If GRID(X,Y-1)=0
- SHOWMINES[X,Y-1]
- End If
- If GRID(X+1,Y)=0
- SHOWMINES[X+1,Y]
- End If
- If GRID(X,Y+1)=0
- SHOWMINES[X,Y+1]
- End If
- GRID(X,Y)=5
-
- End Proc
-
- I'm assuming an empty unchecked square contains 0, and that an
- empty
- checked square contains 5.
-
- Ain't recursion great? :)
-
- --
- GCS -d+ H+ s++:- g+ p? !au a- w+++ !Productions 1995
- v* C+++ UB+++A++++ P++ L++ E+ N+++
- http://satelnet.org/~mentat/
- K+ !W--- M-- V po- Y+ t++ 5+ jx G?
- R tv++ D- B--- e+ u** h f r++ !n y+ "No matter where you go, there
- you are."
-
-
-
-
-
-